home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDPause.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.6 KB  |  185 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDPause - An XFCN to pause CDROM audio play
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDPause.c
  11.     link -sn Main=CDPause -sn STDIO=CDPause ∂
  12.          -sn INTENV=CDPause -rt XFCN=42 ∂
  13.          -m CDPAUSE CDPause.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    APause(short, short);
  28. int        AreWePlaying(short);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDPause
  36.  *
  37.  *  Purpose:        pause audio play
  38.  *
  39.  *  Returns:        result of driver call to pause
  40.  *                    normally 0, but could have parameter error or
  41.  *                    other error if non-existent block is specified
  42.  *
  43.  *  Side Effects:
  44.  *
  45.  *  Description:    We need one parameter (or none):
  46.  *                    1) pauseMode.  This could be either 0 to pause, or
  47.  *                       1 to stop pause and resume play.
  48.  *                    If we don't get this parameter, toggle from the current
  49.  *                    status.
  50.  *                    Get the famous global ioRefNum (from previously
  51.  *                    calling CDOpen())
  52.  *
  53.  ************************************************************************/
  54. pascal void
  55. CDPause(paramPtr)
  56. XCmdBlockPtr    paramPtr;
  57. {
  58.     Str31    returnString;
  59.     OSErr    result;
  60.     short    ioRefNum;
  61.     Handle    refHandle;
  62.     short    pauseMode;
  63.     
  64.     /* Must be one parameter */
  65.     if ((paramPtr->paramCount) > 1)
  66.     {
  67.         /* Report error in parameters by returning -1 */
  68.         NumToStr(paramPtr, (long) -1, &returnString);
  69.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  70.         return;
  71.     }
  72.     
  73.     /* Get the global ioRefNum and convert it. */
  74.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  75.     ioRefNum = atoi(*(refHandle));
  76.     DisposHandle(refHandle);
  77.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  78.     
  79.     if (paramPtr->paramCount == 1)
  80.         pauseMode = atoi(*(paramPtr->params[0]));
  81.     else
  82.         pauseMode = AreWePlaying(ioRefNum);
  83.     
  84.     /* Since the user always thinks 0 means pause, and the driver thinks
  85.     ** 1 is pause for this call, we must switch the meaning of these
  86.     ** two values. 
  87.     */
  88.     if (pauseMode == 0)
  89.         pauseMode = 1;
  90.     else if (pauseMode == 1)
  91.         pauseMode = 0;
  92.     else
  93.     {
  94.         /* Report error in parameters by returning -1 */
  95.         NumToStr(paramPtr, (long) -1, &returnString);
  96.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  97.         return;
  98.     }
  99.  
  100.     result = APause(ioRefNum, pauseMode);
  101.     
  102.     /* Convert result to string & return it as error */
  103.     NumToStr(paramPtr, (long) result, &returnString);
  104.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  105. }
  106.  
  107. /************************************************************************
  108.  *
  109.  *  Function:        APause
  110.  *
  111.  *  Purpose:        pause/resume CD play
  112.  *
  113.  *  Returns:        OSErr.  Probably either
  114.  *                        noErr        everything's hunky-dory!
  115.  *                        paramErr    you messed up the call somehow.
  116.  *
  117.  *  Side Effects:    pauses audio play or resumes it.
  118.  *
  119.  *  Description:    Simply call the driver.
  120.  *
  121.  ************************************************************************/
  122. OSErr
  123. APause(refNum, mode)
  124. short    refNum;
  125. short    mode;
  126. {
  127.     CDPauseParam    myPB;
  128.     OSErr    result;
  129.     
  130.     myPB.ioCompletion = 0;
  131.     myPB.ioNamePtr = (char *) 0;
  132.     myPB.ioVRefNum = 1;
  133.     myPB.ioCRefNum = refNum;
  134.     myPB.csCode = APAUSE;
  135.     myPB.pauseMode = mode;
  136.     
  137.     result = PBControl(&myPB, false);
  138.     return result;
  139. }
  140.  
  141.  
  142. /************************************************************************
  143.  *
  144.  *  Function:        AreWePlaying
  145.  *
  146.  *  Purpose:        return CD audio status
  147.  *
  148.  *  Returns:        a value to indicate whether we are playing or not.
  149.  *                    1 = we're paused
  150.  *                    0 = we're playing, or finished, or whatever.
  151.  *                    Notice that these values are meant to be the same as
  152.  *                    what a user would type to CDPause to get it to play
  153.  *                    or pause.
  154.  *
  155.  *  Side Effects:    none.
  156.  *
  157.  *  Description:    Simply call the driver and return the audio status
  158.  *                    byte that the driver gives us.
  159.  *
  160.  ************************************************************************/
  161. int
  162. AreWePlaying(refNum)
  163. short    refNum;
  164. {
  165.     CDStatusParam    myPB;
  166.     short    result;
  167.     
  168.     myPB.ioCompletion = 0;
  169.     myPB.ioNamePtr = (char *) 0;
  170.     myPB.ioVRefNum = 1;
  171.     myPB.ioCRefNum = refNum;
  172.     myPB.csCode = ASTATUS;
  173.     
  174.     PBControl(&myPB, false);
  175.  
  176.     if (myPB.audioStatus == 1)    /* we're currently paused */
  177.         result = 1;    /* play */
  178.     else
  179.         result = 0;    /* pause */
  180.     return result;
  181. }
  182.  
  183. /* C routines for HyperCard callbacks */
  184. #include <XCmdGlue.inc.c>
  185.